package cn.wh.scheduler;

import cn.wh.job.MrAnalysisJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class MrAnalysisJobScheduler {

    //创建调度器
    private static Scheduler getScheduler() throws SchedulerException {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        return schedulerFactory.getScheduler();
    }
    // 执行任务
    public static void run() throws SchedulerException{
        //创建任务
        JobDetail jobDetail = JobBuilder.newJob(MrAnalysisJob.class).withIdentity("MrAnalysisJob01", "TouSuSuYuan01").build();

        //每秒钟触发一次任务
        CronTrigger trigger = TriggerBuilder.newTrigger().
                withIdentity("triggerName01", "triggerGroup01").
                withSchedule(CronScheduleBuilder.cronSchedule("0 */1 * * * ? *")).
                build();
        Scheduler scheduler = getScheduler();
        //将任务及其触发器放入调度器
        scheduler.scheduleJob(jobDetail, trigger);
        //调度器开始调度任务
        // 启动
        if (!scheduler.isShutdown()) {
            scheduler.start();
        }
    }
}
